//
//  FeebackPageController.m
//  WashForU
//
//  Created by 王俊 on 15/12/7.
//  Copyright © 2015年 王俊. All rights reserved.
//

#import "FeebackPageController.h"

@interface FeebackPageController ()
@property(nonatomic,strong)UITextView      *inputBox;
@property(nonatomic,strong)UIButton        *commitButton;
@property(nonatomic,strong)UILabel         *placeholderLabel;

@end

@implementation FeebackPageController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self customViewSetUp];
    [self customConstrainsAdd];
    [self targetAdd];
}
-(void)viewWillAppear:(BOOL)animated
{
    if ([self.inputBox.text isEqualToString:@""]){
        self.placeholderLabel.hidden = false;
    }

}
/*****************添加视图组件********************/
- (void)customViewSetUp
{
    self.titleLabel.text = @"意见反馈";
    self.inputBox = [[UITextView alloc]init];
    self.commitButton = [[UIButton alloc]init];
    self.placeholderLabel = [[UILabel alloc]init];
    
    
    self.inputBox.backgroundColor = [UIColor whiteColor];
    self.inputBox.layer.borderWidth = 1;
    self.inputBox.layer.cornerRadius = 4;
    self.inputBox.font = [UIFont CustomFont:16];
    self.inputBox.textColor = [UIColor GrayColor_88];
    self.inputBox.layer.borderColor = [UIColor GrayColor_188].CGColor;
    self.inputBox.delegate = self;
    
    self.commitButton.backgroundColor = [UIColor CustomLightBlue];
    [self.commitButton setTitle:@"提交" forState:UIControlStateNormal];
    [self.commitButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.commitButton setTitleColor:[UIColor CustomLightBlue] forState:UIControlStateHighlighted];
    self.commitButton.titleLabel.textAlignment = NSTextAlignmentCenter;
    
    self.placeholderLabel.textColor = [UIColor GrayColor_188];
    self.placeholderLabel.font = self.inputBox.font;
    self.placeholderLabel.text = @"请输入你的宝贵意见，谢谢！";
    
    
    
    [self.view addSubview:self.inputBox];
    [self.view addSubview:self.commitButton];
    [self.view addSubview:self.placeholderLabel];

    
    
    
}
/*******************添加约束**********************/
- (void)customConstrainsAdd
{
    [self.inputBox mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(self.view).offset(20);
        make.top.equalTo(self.upView.mas_bottom).offset(15);
        make.trailing.equalTo(self.view).offset(-20);
        make.height.equalTo(self.view).multipliedBy(0.5);
    }];
    [self.commitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.equalTo(self.inputBox);
        make.top.equalTo(self.inputBox.mas_bottom).offset(20);
        make.height.mas_equalTo(40);
    }];
    [self.placeholderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.inputBox);
        make.leading.equalTo(self.inputBox).offset(5);
        make.height.mas_equalTo(40);
    }];
    
}
/*******************添加事件**********************/
- (void)targetAdd
{
    
    [self.backButton addTarget:self action:@selector(backButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [self.commitButton addTarget:self action:@selector(commitButtonClicked) forControlEvents:UIControlEventTouchUpInside];
}

- (void)commitButtonClicked
{
    if ([self.inputBox.text isEqualToString:@""]) {
        NSLog(@"is nil");
    }
    NSLog(@"%@",self.inputBox.text);
}

- (void)textViewDidBeginEditing:(UITextView *)textView
{
    self.placeholderLabel.hidden = true;
}

- (void)textViewDidEndEditing:(UITextView *)textView
{
    if ([self.inputBox.text isEqualToString:@""]){
        self.placeholderLabel.hidden = false;
    }
}


@end
